/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.inv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dian.common.server.CommonService;
import com.dian.common.utils.Date;
import com.dian.common.utils.ListUtils;
import com.dian.common.utils.MapUtils;
import com.dian.modules.inv.dao.OutLineDao;
import com.dian.modules.inv.entity.OutHeadEntity;
import com.dian.modules.inv.entity.OutLineEntity;
import com.dian.modules.inv.service.OutLineService;
import com.dian.modules.inv.vo.GoodsStockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 出库单明细服务实现类
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-06-11 00:16:18
 */
@Service("OutLineService")
public class OutLineServiceImpl extends ServiceImpl<OutLineDao, OutLineEntity> implements OutLineService {
    @Autowired
    public OutLineService outLineService;
    @Autowired
    public CommonService commonService;

    @Override
    public boolean updateInfo(OutHeadEntity outHeadEntity) {
        List<OutLineEntity> lineList=outHeadEntity.getOutLineEntityList();
        ListUtils.setPropertyValue(lineList,"outId",outHeadEntity.getId());

        this.removeByMap(new MapUtils().put("out_id", outHeadEntity.getId()));
        this.saveBatch(lineList);
        return true;

    }

    @Override
    public boolean deleteInfo(Long id) {
        return this.remove(new QueryWrapper<OutLineEntity>().eq("out_id",id));

    }

    @Override
    public List<OutLineEntity> queryList(Long id) {
        return this.list(new QueryWrapper<OutLineEntity>().eq("out_id",id));

    }

    /**
     * 查询指定商品本月有效入库数量
     * @param goodsStockVO
     * @return
     */
    @Override
    public GoodsStockVO queryOutGoodsQty(GoodsStockVO goodsStockVO){
        return  this.baseMapper.queryOutGoodsQty(
                goodsStockVO.getWarehouseId(),
                new Date().toText2(),
                goodsStockVO.getGoodsId(),
                goodsStockVO.getColorNumber(),
                goodsStockVO.getItemGrade()
        );
    }
}
